package cn.edu.njust.alg;

public class PermImpl {
	
	public static void perm(int[]a, int p, int q){
		if(p==q){
			for(int i=0;i<=q;i++){
				System.out.printf("%2d\t",a[i]);
			}
			System.out.println();
		}else{
			for(int i=p;i<=q;i++){
				swap(a, p, i);
				perm(a, p+1, q);
				swap(a, p, i);
			}
		}
	}
	
	public static void swap(int[]a,int k,int i){
		int temp= a[k];
		a[k] = a[i];
		a[i]=temp;
	}
	
	
	public static void main(String[] args) {

		int[] a = { 3, 45, 6, 78 };

		perm(a, 0, a.length-1);
	}

}
